<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>收入分配</title>
</head>
<body>

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <!--<div class="ibox-title">
                    <h5>收入管理</h5>
                </div>-->
                <div class="ibox-content">
                    <div class="table-responsive">
                        <div class="m-l-xs toolbar" id="budgetincomeList_toolbar">
                            <button class="btn btn-sm btn-primary" type="button"
                                    onclick="budgetincomeListObj.addOrUpdateHandle()"><i
                                    class="fa fa-plus"></i>&nbsp;新增
                            </button>
                            <button class="btn btn-sm btn-primary" type="button"
                                    onclick="budgetincomeListObj.importHandle()"><i
                                    class="fa fa-plus"></i>&nbsp;导入
                            </button>
                        </div>
                        <table id="budgetincomeList_table" class="table table-striped"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页面内容结束-->
<!--弹窗：收入分配-->
<div th:replace="web/budget/cur/budgetin-distribution::budgetincomeDistributionEdit"></div>
<script type="text/javascript">
    $(function () {
        budgetincomeListObj.myTable = $('#budgetincomeList_table').bootstrapTable({
            toolbar: '#budgetincomeList_toolbar',
            pagination: true,
            sidePagination: 'server',
            url: "/budget/budgetincome/list",
            formatNoMatches: function () {  //没有匹配的结果
                return '暂无数据';
            },
            columns: [{
                title: '#',
                align: 'center',
                width: 50,
                formatter: function (value, row, index) {
                    return index + 1;
                }
            }, {
                title: '业务类型',
                width: '100',
                field: 'busiType'
            }, {
                title: '交易金额',
                width: '100',
                field: 'tradeAmount',
                formatter: function (value, row, index) {
                    return $.moneyFormat(value);
                }
            }, {
                title: '交易日期',
                width: '80',
                field: 'transDate'
            }, {
                title: '付款人开户行号',
                width: '120',
                field: 'payerBankNum'
            }, {
                title: '付款人开户行名',
                field: 'payerBankAccount',
                formatter: function (value, row, index) {
                    var maxNum = 20;
                    var str = value;
                    if (value.length > maxNum) {
                        str = value.substring(0, maxNum) + '...';
                    }
                    return str;
                }
            }, {
                title: '付款人账号',
                width: '100',
                field: 'payerAccountNo'
            }, {
                title: '付款人名称',
                width: '140',
                field: 'payerName'
            }, {
                title: '标签',
                width: '80',
                field: 'existTag',
                formatter: function (value, row, index) {
                    return value ? "是" : "否";
                }
            }, {
                title: '分配',
                width: '80',
                field: 'inType',
                formatter: function (value, row, index) {
                    var str = '未分配';
                    if (value == 1) {
                        str = '已分配';
                    } else if (value == 2) {
                        str = '部分分配';
                    }
                    return str;
                }
            }, {
                title: '操作',
                width: 160,
                events: {
                    'click .distribution': function (e, value, row, index) {
                        budgetincomeListObj.distributionHandle(row.id)
                    },
                    'click .tags': function (e, value, row, index) {
                        budgetincomeListObj.tagsHandle(row.id)
                    },
                    'click .edit': function (e, value, row, index) {
                        budgetincomeListObj.addOrUpdateHandle(row.id)
                    },
                    'click .trash': function (e, value, row, index) {
                        budgetincomeListObj.deleteHandle(row.id)
                    }
                },
                formatter: function (value, row, index) {
                    var opers = [];
                    opers.push(`<a class="distribution btn btn-white btn-bitbucket text-success" data-toggle="tooltip" title="分配">
                                    <i class="fa fa-sitemap"></i>
                                </a>`)
                    opers.push(`<a class="tags btn btn-white btn-bitbucket text-success" data-toggle="tooltip" title="标签">
                                    <i class="fa fa-tags"></i>
                                </a>`)
                    opers.push(`<a class="edit btn btn-white btn-bitbucket text-success" data-toggle="tooltip" title="编辑">
                                    <i class="fa fa-edit"></i>
                                </a>`)
                    opers.push(`<a class="trash btn btn-white btn-bitbucket text-success" data-toggle="tooltip" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                    return opers.join('');
                }
            }],
            responseHandler: function (res) {
                return {
                    total: res.page.totalCount,
                    rows: res.page.list
                };
            },
            onLoadSuccess: function (data) {
                $('[data-toggle="tooltip"]').tooltip()
            }
        });
    })
    var budgetincomeListObj = new Object({
        myTable: undefined,
        refreshDataList: function () {
            this.myTable.bootstrapTable('refresh')
        },
        addOrUpdateHandle: function (id) {
            budgetincomeEditObj.init(id);
        },
        importHandle: function () {

        },
        tagsHandle: function (id) {
            budgetincomeTagsEditObj.init(id);
        },
        distributionHandle: function (id) {
            budgetincomeDistributionEditObj.init(id);
        },
        deleteHandle: function (id) {
            let _self = this;
            $.mySwalConfirm(`将删除收入信息，确认吗？`, function () {
                $.myDelete({
                    url: `/budget/budgetincome/delete`,
                    dataType: "json",
                    data: [id],
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            _self.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        }
    })
</script>
</body>
</html>